package Meeting;

import gongju.fuzhiqu;
import kechengsheji.employee.UserDAO;
import kechengsheji.manag.Managpanel;
import kechengsheji.manag.ManangTablePanel;

import javax.swing.*;
import java.awt.*;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;

public class MeetingEditPanel extends JInternalFrame {

    public MeetingEditPanel(Object id) {
        super("会议预约", true, true, true, true);
        this.setVisible(true);

        JPanel panel = new JPanel();
        panel.setBackground(Color.WHITE);
        this.add(panel);

        Box box = Box.createVerticalBox();
        panel.add(box);
        box.add(Box.createVerticalStrut(55));

        Box box2 = Box.createHorizontalBox();
        box2.add(new JLabel("会议内容"));
        JComboBox<String> field1 = new JComboBox<>();
        box2.add(field1);
        for (String dept : fuzhiqu.bumen2) {
            field1.addItem(dept);
        }
        box.add(box2);

        Box box3 = Box.createHorizontalBox();
        box3.add(new JLabel("会议地点"));
        JTextField field2 = new JTextField(10);
        box3.add(field2);
        box.add(box3);
        box.add(Box.createVerticalStrut(5));

        if (id != null) {
            Object[] data = MeetingDAO.findById(id);
            field1.setSelectedItem(data[2]);
            field2.setText(data[2].toString());
        }

        JButton btn = new JButton("提交");
        Box boxBtn = Box.createHorizontalBox();
        boxBtn.add(Box.createHorizontalStrut(40));
        boxBtn.add(btn);
        box.add(boxBtn);

        btn.addMouseListener(new MouseAdapter() {
            public void mouseClicked(MouseEvent e) {
                Object[] data = new Object[]{id, field1.getSelectedItem(), field2.getText()};
                if (id == null) {
                    MeetingDAO.add(data);
                }
                Managpanel.setContent(new ManangTablePanel());
            }
        });
    }
}
